/**
 * Created by Administrator on 2018/5/29.
 */
/**
 * Created by Administrator on 2017/11/14.
 */

/*
 Require:    baidu.api    （"http://api.map.baidu.com/api?v=2.0&ak=....."）
 jquery.min.js
 jquery.tipso.min.js
 jquery.tipso.min.css
 Data Format:
 [
 {"park":"东郊文化创意集聚区","coord":["104.050623","30.663351"], "region":"成华区"},
 {"park":"成都东客站枢纽经济集聚区","coord":["104.140357","30.62933"], "region":"成华区"}
 ]

 */

function MapPark(viewId){
    var MP = this;
    var _Map = null;
    MP.version = 1.2;
    MP.viewId = viewId || "";
    MP.map = Map;
    MP.center = [104.0316, 30.7813];
    MP.data = [ ];
    MP.cachePark = { };
    MP.tagclasss = { };

    //// 加载园区数据
    MP.loadParkData = function(parks){
        MP.data = parks;
        MP.data.forEach(function(p){
            MP.cachePark[p.park] = p;
        });
    };

    //// 初始化
    MP.init = function(_viewId){
        if(_viewId)MP.viewId = _viewId;
        _Map = new BMap.Map(MP.viewId, { minZoom:4.5 });
        _Map.centerAndZoom(new BMap.Point(MP.center[0], MP.center[1]), 10);
        var  mapStyle ={
            features: ["road", "building","water","land"],      //隐藏地图上的poi
            style : "light"                                     //设置地图风格
        };
        _Map.setMapStyle(mapStyle);

        // 添加地图类型控件
        _Map.addControl(new BMap.MapTypeControl({ mapTypes:[ BMAP_NORMAL_MAP, BMAP_HYBRID_MAP ]}));
        _Map.setCurrentCity("成都");
        _Map.enableScrollWheelZoom(true);
        MP.addPolygon("成都", "#8B0000", "");
    };


    ////// 圈行政区域
    MP.addPolygon = function (name, borderColor, fillColor, weight){
        if(borderColor=="")borderColor = undefined;
        var pyOption = {strokeWeight: weight || 3, strokeColor: borderColor || "#EEAEEE", fillColor:fillColor || '', fillOpacity:0};
        var bdary = new BMap.Boundary();
        bdary.get(name, function(rs){                           // 获取行政区域
            // map.clearOverlays();
            rs.boundaries.forEach(function(d){
                _Map.addOverlay(new BMap.Polygon(d, pyOption));  // 添加覆盖物
            });
        });
    };


    //// 根据索引获取图标
    function _getIcon(index){
        index = index || 22;
        var myIcon = new BMap.Icon("../imgs/markers.png", new BMap.Size(23, 25), {
            offset: new BMap.Size(10, 25),
            imageOffset: new BMap.Size(0, 0 - index * 25)
        });
        return myIcon;
    }



    this.init();
    this.addRegionPolygon();
    this.initStyle();
}


var mapPark = MapPark.prototype;



//// 区域标注
mapPark.addRegionPolygon = function (){
    var MP = this;
    var regions = ["金牛区", "成华区", "青羊区", "金牛区", "武侯区", "锦江区", "郫都区", "温江区",
        "新都区", "龙泉驿区", "双流区", "青白江区", "金堂县", "简阳市", "崇州市", "都江堰市", "新津县",
        "浦江县", "邛崃市", "大邑县", "彭州市"];
    regions.forEach(function(d){
        //MP.addPolygon(d, "#CD6889", "#6CA6CD", 1);
    });
};

//// 样式预加载
mapPark.initStyle = function (){
    var MP = this;
    $("#" + MP.viewId).on("mouseover", '.mapTitle', function() {
        var title = $(this).attr("data-tipso");
        $(this).tipso({
            content: title,
            width:300,
            delay:0,
            background: "#fff",
            color:'#000'
        });
    });
};



// -----------------------------------------------------------------------------------------------------------
